import { setTokenLocal, getTokenLocal, delTokenLocal } from "@/utils/storage"
import { loginAPI } from "@/api/user"
export default ({
    namespaced: true,
    state: {
        // token: "",
        // state 中 token 持久化
        token: getTokenLocal(),
    },
    getters: {
    },
    mutations: {
        setToken(state, token) {
            state.token = token;
            setTokenLocal(token);
        },
        delToken(state) {
            state.token = "";
            delTokenLocal()
        }
    },
    actions: {
        async login(context, data) {
            console.log(data);
            const res = await loginAPI(data)
            console.log(res);
            context.commit("setToken", res.data.token)
        },
        logout(context){
            context.commit('delToken')
        }
    },
    modules: {
    }
})